import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { DelegateSettingRule } from "./DelegateSettingRule";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SystemSetter } from "../../system/SystemSetter";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class DelegateGetSettingWindow
    
    export  class DelegateGetSettingWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._dic = new Map<any, any> /* flash.utils.Dictionary */();
            this.setSize(300, 240);
            this.titleHeight = 25;
            this.title = Language.getString(69685);
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            ObjCreate.createBg(18, 36, 264, 193, this);
            this._vec = new Vector.<GCheckBox>();
            this._all = this.createGCheckBox(27, 50, Language.getString(69686), DelegateSettingRule.ALL);
            this.createGCheckBox(27, 70, Language.getString(69687), DelegateSettingRule.PurpleEquip);
            this.createGCheckBox(27, 90, Language.getString(69688), DelegateSettingRule.PurpleProp);
            this._allProp = this.createGCheckBox(27, 110, Language.getString(69690), DelegateSettingRule.AllProp);
            this.createGCheckBox(27, 130, Language.getString(69691), DelegateSettingRule.PropStren);
            this.createGCheckBox(95, 130, Language.getString(69692), DelegateSettingRule.PropTie);
            this.createGCheckBox(165, 130, Language.getString(69693), DelegateSettingRule.PropAdvance);
            this.createGCheckBox(27, 150, Language.getString(69694), DelegateSettingRule.PropKill);
            this.createGCheckBox(95, 150, Language.getString(69695), DelegateSettingRule.PropSoap);
            this.createGCheckBox(165, 150, Language.getString(69696), DelegateSettingRule.PropGouhuo);
            this.createGCheckBox(27, 170, Language.getString(69697), DelegateSettingRule.PropChange);
            this.createGCheckBox(95, 170, Language.getString(69700), DelegateSettingRule.Jewel);
            this.createGCheckBox(165, 170, Language.getString(69701), DelegateSettingRule.Illustrate);
            this._saveBtn = ObjCreate.createGButton(Language.getString(69698), 194, 192, 75, 26, this);
            this._saveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSaveBtnClick);
            return;
        }

        /* internal  */onSaveBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._change = false;
            Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow));
            this.hide();
            return;
        }

        /* internal  */createGCheckBox(arg1: int, arg2: int, arg3: string, arg4: int): GCheckBox
        {
            var loc1=null;
            if (DelegateSettingRule.isProp(arg4)) 
            {
                loc1 = "GCheckBox3";
            }
            else 
            {
                loc1 = "GCheckBox";
            }
            var loc2;
            (loc2 = ObjCreate.createCheckBox(arg3, arg1, arg2, 150, 20, this, loc1)).name = String(arg4);
            loc2.addEventListener(flash.events.Event.CHANGE, this.onCheckBoxChange);
            this._vec.push(loc2);
            return loc2;
        }

        /* internal  */onCheckBoxChange(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            this._change = true;
            if (this._all.selected) 
            {
                this.enableAll(false);
            }
            else 
            {
                this.enableAll(true);
                this.enableAllProp(this._allProp.selected);
            }
            if (arg1 && arg1.currentTarget == this._allProp) 
            {
                this.selectAllProp(this._allProp.selected);
            }
            loc1 = 0;
            while (loc1 < this._vec.length) 
            {
                this._dic[this._vec[loc1].name] = this._vec[loc1].selected;
                ++loc1;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.DelegateSettingInfo, this._dic));
            return;
        }

        /* internal  */enableAll(arg1: Boolean): void
        {
            var loc1=0;
            loc1 = 1;
            while (loc1 < this._vec.length) 
            {
                this._vec[loc1].enabled = arg1;
                ++loc1;
            }
            return;
        }

        /* internal  */enableAllProp(arg1: Boolean): void
        {
            var loc1=0;
            loc1 = 0;
            while (loc1 < this._vec.length) 
            {
                if (DelegateSettingRule.isProp(parseInt(this._vec[loc1].name))) 
                {
                    this._vec[loc1].enabled = arg1;
                }
                ++loc1;
            }
            return;
        }

        /* internal  */selectAllProp(arg1: Boolean): void
        {
            var loc1=0;
            loc1 = 0;
            while (loc1 < this._vec.length) 
            {
                if (DelegateSettingRule.isProp(parseInt(this._vec[loc1].name))) 
                {
                    this._vec[loc1].selected = arg1;
                }
                ++loc1;
            }
            return;
        }

        public updateStatus(): void
        {
            var loc2=0;
            var loc1=SystemSetter.localSetter.delegateSetting;
            loc2 = 0;
            while (loc2 < loc1.length) 
            {
                this._dic[loc1[loc2]] = true;
                ++loc2;
            }
            loc2 = 0;
            while (loc2 < this._vec.length) 
            {
                this._vec[loc2].selected = this._dic[this._vec[loc2].name] != null ? this._dic[this._vec[loc2].name] : false;
                ++loc2;
            }
            this.onCheckBoxChange(null);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updateStatus();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            return;
        }

        /* internal */ /* var */_dic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_change: Boolean=false;

        /* internal */ /* var */_all: GCheckBox;

        /* internal */ /* var */_allProp: GCheckBox;

        /* internal */ /* var */_vec: Vector.<GCheckBox>;

        /* internal */ /* var */_saveBtn: GButton;
    }
